<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="description" content="">
<meta name="author" content="ThemeBucket">
<link rel="shortcut icon" type="image/x-icon"
	href="${ctxPath}/static/images/lukk.ico" media="screen" />
<link rel="icon" href="${ctxPath}/static/images/lukk.ico"
	type="image/x-icon" />
<link rel="bookmark" href="${ctxPath}/static/images/lukk.ico"
	type="image/x-icon" />

<title>管理页面</title>
</head>
<body class="sticky-header"
	onload="indexmenu('${oneMenu}','${twoMenu}');">
	<%@ include file="../index/index.jsp"%>
	<section>
		<div class="main-content" style="overflow-y: auto">
			<!-- 地址栏-->
			<div class="page-heading">
				<h3>鹿客帮</h3>
				<ul class="breadcrumb">
					<li><a>审核管理 </a></li>
					<li class="active">开始审核</li>
				</ul>
			</div>
			<div class="panel-body" style="padding-bottom: 0px;">
				<div class="panel panel-default">
					<div class="panel-heading">查询条件</div>
					<div class="panel-body">
						<form id="formSearch" class="form-horizontal">
							<div class="form-group" style="margin-top: 10px">
								<div class="form-inline col-sm-2">
									名称：<input type="text" class="form-control"
										id="txt_search_workerName">
								</div>
								<div class="form-inline col-sm-2">
									手机：<input type="text" class="form-control"
										id="txt_search_phoneNumber">
								</div>
								<div class="form-inline col-sm-2">
									省份： <select id="allocatedProvinceSelect" name=""
										class="selectpicker show-tick form-control"
										data-live-search="false">
									</select>
								</div>
								<div class="form-inline col-sm-4">
									时间段：&nbsp;&nbsp;<input size="" type="text"
										class="form_datetime-adv form-control" style="width: 170px"
										readonly id="beginTime"> &nbsp;&nbsp;&nbsp; 到：<input
										size="" type="text" readonly
										class="form_datetime-adv form-control" style="width: 170px"
										id="endTime">
								</div>
								<div class="form-inline col-sm-2" style="text-align: left;">
									<button type="button" style="margin-left: 50px" id="btn_query"
										class="btn btn-primary">查询</button>
								</div>
							</div>
						</form>
					</div>
				</div>
				<table id="tb_worker"></table>
			</div>

		</div>
	</section>
	<!--  查看详细modal  -->
	<div class="modal fade" style="top: 100px;" id="viewWorkerDetialModal"
		tabindex="-1" role="dialog"
		aria-labelledby="viewWorkerDetialModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="viewWorkerDetialModalLabel">查看师傅的详细信息</h4>
				</div>
				<div class="modal-body">
					<form class="form-horizontal" id="modifyPotentialWorkerForm"
						role="form">
						<input type="hidden" name="id" id="txt_workerID">
						<div class="form-group">
							<label for="txt_workerName" class="col-sm-2 control-label">师傅名称</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="txt_workerName">
							</div>
						</div>
						<div class="form-group">
							<label for="txt_phoneNumber" class="col-sm-2 control-label">师傅手机</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="txt_phoneNumber">
							</div>
						</div>
						<div class="form-group">
							<label for="txt_phoneNumber" class="col-sm-2 control-label">绑定银行</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="txt_boundBank">
							</div>
						</div>
						<div class="form-group">
							<label for="txt_phoneNumber" class="col-sm-2 control-label">银行卡号</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="txt_boundNumber">
							</div>
						</div>
						<div class="form-group">
							<label for="txt_phoneNumber" class="col-sm-2 control-label">上传头像</label>
							<div class="col-sm-10">
								<img src="" id="workerImg" alt="Cinque Terre">
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭
					</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal -->
	</div>
	<div class="modal fade" style="top: 100px;"
		id="verifyWorkerNotThroughModal" tabindex="-1" role="dialog"
		aria-labelledby="verifyWorkerNotThroughModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="verifyWorkerNotThroughModalLabel">审核未通过信息</h4>
				</div>
				<div class="modal-body">
					<form class="form-horizontal" id="modifyPotentialWorkerForm"
						role="form">
						<input type="hidden" name="id" id="txt_workerID">
						<div class="form-group">
							<label for="txt_reason" class="col-sm-3 control-label">未通过原因：</label>
							<div class="col-sm-9">
								<select class="form-control selectpicker" id="sendMessageTitle"
									onchange="verifySelectChange(this)">
									<option value='0'>上传头像不符合要求</option>
									<option value='1'>编辑姓名不符合要求</option>
									<option value='2'>工种不匹配</option>
									<option value='3'>上传头像和编辑姓名都不符合要求</option>
								</select>
							</div>
						</div>
						<div class="form-group">
							<label for="txt_verifyWorkerName" class="col-sm-3 control-label">师傅姓名：</label>
							<div class="col-sm-9">
								<input type="text" class="form-control"
									id="txt_verifyWorkerName">
							</div>
						</div>
						<div class="form-group">
							<label for="txt_phoneNumber" class="col-sm-3 control-label">发送信息：</label>
							<div class="col-sm-9">
								<textarea class="form-control" id="sendMessageTextArea" rows="5">【鹿客帮】您注册的“鹿客帮师傅版”信息审核未通过，未通过原因为上传头像不符合要求，请打开软件重写填写。
								</textarea>
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭
					</button>
					<button type="button" onclick="verifyWorkerNotThroughSubmit()"
						class="btn btn-primary">确认拒绝</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal -->
	</div>
</body>
<script type="text/javascript"
	src="${ctxPath}/static/js/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
<!--pickers initialization-->
<script
	src="${ctxPath}/static/js/bootstrap-datetimepicker/pickers-init.js"></script>
<!-- tables插件的引用 -->
<script src="${ctxPath}/static/js/bootstrap-table/bootstrap-table.js"></script>
<link href="${ctxPath}/static/js/bootstrap-table/bootstrap-table.css"
	rel="stylesheet" />
<script
	src="${ctxPath}/static/js/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>

<script type="text/javascript">
	//查看待审核员工详细信息
	function viewWorkerDetialModalOpen(id) {
		var viewRow = $('#tb_worker').bootstrapTable(
				'getRowByUniqueId', id);
		$("#txt_workerName").val(viewRow.name);
		$("#txt_phoneNumber").val(viewRow.phone);
		$("#txt_boundBank").val(viewRow.boundBank);
		$("#txt_boundNumber").val(viewRow.boundNumber);
		$("#workerImg").attr(
				"src",
				"http://okwc9gyzs.bkt.clouddn.com/" + viewRow.headImg
						+ "?imageView2/1/w/400/h/300");
		$('#viewWorkerDetialModal').modal('show');
	}
	var TableInit = function() {
		var oTableInit = new Object();
		//初始化Table
		oTableInit.Init = function() {
			$('#tb_worker')
					.bootstrapTable(
							{
								url : '${ctxPath}/worker/queryByProvinceAndName', //请求后台的URL（*）
								method : 'post', //请求方式（*）
								toolbar : '#toolbar', //工具按钮用哪个容器
								striped : true, //是否显示行间隔色
								cache : false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
								pagination : true, //是否显示分页（*）
								sortable : false, //是否启用排序
								sortName : 'join_date',
								sortOrder : "desc", //排序方式
								queryParams : oTableInit.queryParams,//传递参数（*）
								sidePagination : "server", //分页方式：client客户端分页，server服务端分页（*）
								pageNumber : 1, //初始化加载第一页，默认第一页
								pageSize : 8, //每页的记录行数（*）
								pageList : [ 8, 25, 50, 100 ],
								search : false, //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
								strictSearch : false,
								showColumns : false, //是否显示所有的列
								showRefresh : true, //是否显示刷新按钮
								minimumCountColumns : 2, //最少允许的列数
								clickToSelect : false, //是否启用点击选中行
								height : 600, //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
								uniqueId : "workerId", //每一行的唯一标识，一般为主键列
								showToggle : true, //是否显示详细视图和列表视图的切换按钮
								cardView : false, //是否显示详细视图
								detailView : false, //是否显示父子表
								contentType : 'application/x-www-form-urlencoded; charset=UTF-8',
								columns : [
										{
											field : 'name',
											title : '师傅名称',
											width : '8%',
											align : "center"
										},
										{
											field : 'workerSpace',
											title : '工作区域',
											width : '15%'
										},
										{
											field : 'phone',
											title : '师傅手机',
											width : '10%',
											align : "center"
										},
										{
											field : 'registerDate',
											title : '注册时间',
											width : '10%'
										},
										{
											field : 'boundBank',
											title : '绑定银行',
											width : '10%'
										},
										{
											field : 'age',
											title : '工龄',
											width : '8%'
										},
										{
											field : 'tag',
											title : '查看详细信息',
											width : '10%',
											formatter : function(value, row,
													index) {
												return "<button class='btn btn-info btn-xs' onclick='javascript:viewWorkerDetialModalOpen("
														+ row.workerId
														+ ")'>查看详细信息</button>";
											}
										},
										{
											field : 'tag2',
											title : '审核操作',
											width : '20%',
											formatter : function(value, row,
													index) {
												return "<button class='btn btn-success btn-xs' onclick='javascript:verifyWorkerThrough("
														+ row.workerId
														+ ")'>审核通过</button>&nbsp;&nbsp;&nbsp;<button class='btn btn-danger btn-xs' onclick='javascript:verifyWorkerNotThroughModalOpen("
														+ row.workerId
														+ ")'>残忍拒绝</button>";
											}
										}, ]
							});
		};

		//得到查询的参数
		oTableInit.queryParams = function(params) {
			var temp = { //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
				limit : params.limit, //页面大小
				offset : params.offset, //页码
				order : params.order,
				sort : params.sort,
				beginTime : $("#beginTime").val(),
				endTime : $("#endTime").val(),
				workerName : $("#txt_search_workerName").val(),
				provinceCode : $("#allocatedProvinceSelect").val(),
				phoneNumber : $("#txt_search_phoneNumber").val(),
				status : 0
			};
			return temp;
		};
		return oTableInit;
	};
	//审核通过
	function verifyWorkerThrough(id) {
		Ewin.confirm({
			message : "您确定要通过他的注册申请吗？申请通过后会发送一条短信！！！ "
		}).on(
				function(e) {
					if (!e) {
						return;
					} else {
						var viewRow = $('#tb_worker').bootstrapTable(
								'getRowByUniqueId', id);
						$.post('${ctxPath}/worker/updateWorkerStatus', {
							workerId : id,
							phone : viewRow.phone,
							status : 1
						}, function(data) {
							toastr.success('已经操作成功！');
							$("#tb_worker").bootstrapTable('refresh');
						});
					}
				});
	}
	function verifyWorkerNotThroughSubmit() {
		Ewin.confirm({
			message : "您确定要残忍的拒绝他的注册申请吗！！！ "
		}).on(function(e) {
			if (!e) {
				return;
			} else {
				$.post('${ctxPath}/worker/updateWorkerStatus', {
					workerId : workerId,
					phone : phone,
					messageType : $('#sendMessageTitle').val(),
					status : 2
				}, function(data) {
					toastr.success('已经操作成功！');
					$("#tb_worker").bootstrapTable('refresh');
					$('#verifyWorkerNotThroughModal').modal('hide');
				});
			}
		});
	}
	var workerId;
	var phone;
	//审核不通过
	function verifyWorkerNotThroughModalOpen(id) {
		var viewRow = $('#tb_worker').bootstrapTable(
				'getRowByUniqueId', id);
		phone = viewRow.phone;
		workerId = id;
		var viewRow = $('#tb_worker').bootstrapTable(
				'getRowByUniqueId', id);
		$("#txt_verifyWorkerName").val(viewRow.name);
		$('#verifyWorkerNotThroughModal').modal('show');
	}
	$(function() {
		$('#endTime').datetimepicker('setStartDate', null);
		$('#beginTime').datetimepicker('setStartDate', null);
		$.post('${ctxPath}/province/queryAllocatedProvinces', function(data) {
			$("#allocatedProvinceSelect").append(
					"<option value='0'>全部省份" + "</option>");
			$(data).each(
					function(index, currData) {
						$("#allocatedProvinceSelect").append(
								"<option value="+currData.areaCode+">"
										+ currData.name + "</option>");
					});
			//1.初始化Table
			var oTable = new TableInit();
			oTable.Init();
			$("#btn_query").click(function() {
				var opt = {
					
					pageNumber : 1,
					query : {
						offset : 0
					}
				};
				//从新开始计数
				$("#tb_worker").bootstrapTable('refresh', opt);
			});
		});
	});
	function verifySelectChange(select) {
		if ($(select).val() == 0) {
			$('#sendMessageTextArea').val(
					"【鹿客帮】您注册的“鹿客帮师傅版”信息审核未通过，未通过原因为上传头像不符合要求，请打开软件重写填写。");
		} else if ($(select).val() == 1) {
			$('#sendMessageTextArea').val(
					"【鹿客帮】您注册的“鹿客帮师傅版”信息审核未通过，未通过原因为编辑姓名不符合要求，请打开软件重写填写。");
		} else if ($(select).val() == 3) {
			$('#sendMessageTextArea')
					.val(
							"【鹿客帮】您注册的“鹿客帮师傅版”信息审核未通过，未通过原因为上传头像和编辑姓名都不符合要求，请打开软件重写填写。");
		} else {
			$('#sendMessageTextArea').val(
					"【鹿客帮】您注册的“鹿客帮师傅版”信息审核未通过，未通过原因为工种不匹配，请打开软件重写填写。");
		}
	}
</script>
<script src="${ctxPath}/static/js/jquery.nicescroll.js"></script>
</html>
